import React from 'react';
import { connect } from 'dva';
import Comp from '../component/Comp';
class ProductWarn extends React.Component {
  constructor() {
    super();
    this.state = {
      data: null,
    };
  }
  componentDidMount() {
    const { dispatch } = this.props;
    this.mounted = true;
    dispatch({
      type: 'OperatePlatformM/queryProductTimeArrive',
      payload: {
        due: 1,
      },
      callback: (res) => {
        if (this.mounted) {
          if (res && res.data && res.data.length) {
            let list = res.data;
            let newArr = null;
            // if(list.length>=10){
            //     newArr = list.slice(0,10);
            // }else{
            //     newArr = list;
            // }
            newArr = list;
            for (var i = 0; i < newArr.length; i++) {
              newArr[i].name = newArr[i].title;
              newArr[i].code = newArr[i].value;
            }
            this.setState({
              data: newArr,
            });
          } else {
            this.setState({
              data: [],
            });
          }
        }
      },
    });
  }
  componentWillUnmount() {
    this.mounted = false;
  }
  render() {
    const { loading } = this.props;
    return <Comp title='产品到期提醒' hasMore={false} refs='swiper-containerResaleProduct' refsPag='swiper-pagination' loading={loading} slideArr={this.state.data}></Comp>;
  }
}
export default connect(({ OperatePlatformM, loading }) => ({ OperatePlatformM, loading: loading.effects['OperatePlatformM/queryProductTimeArrive'] }))(ProductWarn);
